package saeildamil.Ch18.communication;

import javax.swing.JOptionPane;

public class CalcPiThread extends Thread {
	SharedArea sharedArea;

	public CalcPiThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}

	@Override
	public void run() {
		double total = 0;
		for (int cnt = 1; cnt < 1000000; cnt += 2) {
			if(cnt /2 %2 ==0){
				total += 1.0/cnt;
			}else{
				total -= 1.0/cnt;
			}
		}
		sharedArea.result = total * 4;
		sharedArea.isReady = true;
		JOptionPane.showMessageDialog(null, "원주율(Pi) 계산완료");
		synchronized (sharedArea) {
			JOptionPane.showMessageDialog(null, "대기 중인 PrintPiThread에게 전송");
			sharedArea.notifyAll(); //sharedArea에서 wait()에의해 대기하고 있는 쓰레드에게 신호보냄
		}
	}

}
